home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / fillbytes.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  2.0 KB  |  94 lines

  1. /* @(#)fillbytes.c    1.10 00/04/12 Copyright 1987 J. Schilling */
  2. /*
  3.  *    fill memory with data
  4.  *
  5.  *    Copyright (c) 1987 J. Schilling
  6.  */
  7. /*
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2, or (at your option)
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; see the file COPYING.  If not, write to
  20.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <standard.h>
  24. #include <align.h>
  25.  
  26. #define    DO8(a)    a;a;a;a;a;a;a;a;
  27.  
  28. #define    cval    ((char) lval)
  29.  
  30. #ifdef    PROTOTYPES
  31. char *fillbytes(void *tov, int cnt, char val)
  32. #else
  33. char *fillbytes(tov, cnt, val)
  34.     void    *tov;
  35.     int    cnt;
  36.     char    val;
  37. #endif
  38. {
  39.     register char    *to = (char *)tov;
  40.     register int    n;
  41.     register long    lval;
  42.  
  43.     /*
  44.      * If we change cnt to be unsigned, check for == instead of <=
  45.      */
  46.     if ((n = cnt) <= 0)
  47.         return (to);
  48.  
  49.     lval = val & 0xFF;
  50.  
  51.     while (!laligned(to)) {
  52.         *to++ = cval;
  53.         n--;
  54.     }
  55.  
  56.     if (n >= (int)(8 * sizeof(long))) {
  57.         register int rem = n % (8 * sizeof (long));
  58.  
  59.         lval |= (lval<<8);
  60.         lval |= (lval<<16);
  61. #if SIZE_LONG > SIZE_INT
  62.         lval |= (lval<<32);
  63. #endif
  64.  
  65.         n /= (8 * sizeof (long));
  66.         {
  67.             register long *tol = (long *)to;
  68.  
  69.             do {
  70.                 DO8 (*tol++ = lval);
  71.             } while (--n > 0);
  72.  
  73.             to = (char *)tol;
  74.         }
  75.         n = rem;
  76.  
  77.         if (n >= 8) {
  78.             n -= 8;
  79.             do {
  80.                 DO8 (*to++ = cval);
  81.             } while ((n -= 8) >= 0);
  82.             n += 8;
  83.         }
  84.         if (n > 0) do {
  85.             *to++ = cval;
  86.         } while (--n > 0);
  87.         return (to);
  88.     }
  89.     if (n > 0) do {
  90.         *to++ = cval;
  91.     } while (--n > 0);
  92.     return (to);
  93. }
  94.